<?php

class whiteboard
{
	public $sessId ;
	public $userName ;
	public $basePath ;
	public $width ;
	public $height;
	public $fck_instance;

	public function __construct( $sessId )
 	{
		$this->sessId		= $sessId ;
		$this->username		= "guest" ;
		$this->basePath		= "http://" . $_SERVER['SERVER_NAME'] . "/whiteboard/";		
		$this->fullPath		= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
		$this->width		= 600 ;
		$this->height		= 592 ;
		$this->hashkey		= "demo";
	}

	public function Create()
	{
		$fullPath = "http://whiteboard.tutortrove.com/drawing/play.php?pathname=" . htmlentities($this->fullPath) . "&hashkey={$this->hashkey}&session_hash={$this->sessId}&user_id={$this->username}&width={$this->width}&height={$this->height}";
		$iframe_hash = md5(time()); //so that the iframe isn't preloaded to a random page
?>
<script type='text/javascript' src='<?=$this->basePath?>fck_draw.js'></script>
<script type='text/javascript'>
		var lastId = location.hash;
		function checkForMessages(){
			if(location.hash != lastId){
				lastId = location.hash;
				var information = lastId.split("$");
				
				var img_src = "http://luberoff.com/whiteboard/images/" + information[0].substr(1) + ".png";
				var page_number = information[1];
				var iframe_id = "<?=$this->fck_instance?>___Frame";
				close_whiteboard();
				if (document.all) {
				  document.getElementById(iframe_id).contentWindow.image_uploaded(img_src, page_number);
				} else {
				//if Netscape 6+
				  document.getElementById(iframe_id).contentDocument.defaultView.image_uploaded(img_src, page_number);
				}
			}
		}

        function sendUiMessage(message){
			var iwin;
                        if(navigator.userAgent.indexOf("Safari") != -1){
                                iwin = frames["<?=$iframe_hash?>"].location = "<?=$fullPath?>#" + message + "-" + Math.random();
                        }else{
                                document.getElementById("whiteboard_iframe").contentWindow.location = "<?=$fullPath?>#" + message; 
                        }
                }		
		setInterval(checkForMessages, 200);
</script>

<link rel='stylesheet' type='text/css' href='<?=$this->basePath?>fck_draw.css'></script>
 <div id='whiteboard_cover' class='hidden_element'>&nbsp;</div>
 <table id='whiteboard_table' class='hidden_element' onclick='close_whiteboard()'><tr><td align='center' valign='middle'>
 <iframe id='whiteboard_iframe' class='hidden_element' name='<?=$iframe_hash?>' src='<?=$fullPath?>' allowtransparency='true' style='border:4px solid #888; height:<?=$this->height?>px; width:<?=$this->width?>px;' scrolling="no" frameborder='0'></iframe>
 </td></tr></table>
 
 
<?php
	}
}

